home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / muds / lpmud312.tar / lpmud312 / dumpstat.c < prev    next >
C/C++ Source or Header  |  1991-10-31  |  2KB  |  73 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. #include "lint.h"
  5. #include "interpret.h"
  6. #include "object.h"
  7. #include "exec.h"
  8. /*
  9.  * Write statistics about objects on file.
  10.  */
  11.  
  12. extern struct object *obj_list;
  13.  
  14. static int svalue_size(v)
  15.     struct svalue *v;
  16. {
  17.     int i, total;
  18.  
  19.     switch(v->type) {
  20.     case T_OBJECT:
  21.     case T_NUMBER:
  22.     return 0;
  23.     case T_STRING:
  24.     return strlen(v->u.string) + 4; /* Includes some malloc overhead. */
  25.     case T_POINTER:
  26.     for (i=0, total = 0; i < v->u.vec->size; i++) {
  27.         total += svalue_size(&v->u.vec->item[i]) + sizeof (struct svalue);
  28.     }
  29.     return total;
  30.     default:
  31.     fatal("Illegal type: %d\n", v->type);
  32.     }
  33.     /*NOTREACHED*/
  34. #ifdef lint
  35.     return 0;
  36. #endif
  37. }
  38.  
  39. static int data_size(ob)
  40.     struct object *ob;
  41. {
  42.     int total = 0, i;
  43.     if (ob->prog) {
  44.         for (i = 0; i < ob->prog->num_variables; i++)
  45.             total += svalue_size(&ob->variables[i]) + sizeof (struct svalue);
  46.     }
  47.     return total;
  48. }
  49.  
  50. void dumpstat() {
  51.     FILE *f;
  52.     struct object *ob;
  53.  
  54.     f = fopen("OBJ_DUMP", "w");
  55.     if (f == 0)
  56.     return;
  57.     add_message("Dumping to OBJ_DUMP ...");
  58.     for (ob = obj_list; ob; ob = ob->next_all) {
  59.     int tmp;
  60.     if (ob->prog && (ob->prog->ref == 1 || !(ob->flags & O_CLONE)))
  61.         tmp = ob->prog->total_size;
  62.     else
  63.         tmp = 0;
  64.     fprintf(f, "%-20s %5d ref %2d %s %s (%ld) %s\n", ob->name,
  65.         tmp + data_size(ob) + sizeof (struct object), ob->ref,
  66.         ob->flags & O_HEART_BEAT ? "HB" : "  ",
  67.         ob->super ? ob->super->name : "--",/*ob->cpu*/ 0,
  68.         ob->swap_num >=0 ? "SWAPPED" : "");
  69.     }
  70.     add_message("done.\n");
  71.     fclose(f);
  72. }
  73.